﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sustainalytics.Utils
{
    public class AggregateFileSystemConfig
    {
        public IEnumerable<string> RootDirs { get; set; }

        public IEnumerable<string> CommonPaths { get; set; }


        public static AggregateFileSystemConfig FromJsonPath(string jsonPath)
        {
            var fi = new FileInfo(jsonPath);

            using (var fs = fi.OpenRead())
            {
                var config = FromJsonStream(fs);
                return config;
            }
        }

        public static AggregateFileSystemConfig FromJsonStream(Stream jsonStream)
        {
            string jsonStr;

            using (StreamReader sr = new StreamReader(jsonStream))
            {
                jsonStr = sr.ReadToEnd();
            }

            var config = FromJsonString(jsonStr);

            return config;
        }

        public static AggregateFileSystemConfig FromJsonString(string jsonStr)
        {
            var config = JsonConvert.DeserializeObject<AggregateFileSystemConfig>(jsonStr);
            return config;
        }
    }
}
